<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/date_time/constrained_value.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/date_time</a> - constrained_value.hpp<span style="font-size: 80%;"> (source / <a href="constrained_value.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">6</td>
            <td class="headerCovTableEntry">10</td>
            <td class="headerCovTableEntryLo">60.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">3</td>
            <td class="headerCovTableEntry">6</td>
            <td class="headerCovTableEntryLo">50.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifndef CONSTRAINED_VALUE_HPP___</a>
<span class="lineNum">       2 </span>            : #define CONSTRAINED_VALUE_HPP___
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
<span class="lineNum">       5 </span>            :  * Use, modification and distribution is subject to the 
<span class="lineNum">       6 </span>            :  * Boost Software License, Version 1.0. (See accompanying
<span class="lineNum">       7 </span>            :  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       8 </span>            :  * Author: Jeff Garland 
<span class="lineNum">       9 </span>            :  * $Date$
<span class="lineNum">      10 </span>            :  */
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : #include &lt;exception&gt;
<span class="lineNum">      13 </span>            : #include &lt;stdexcept&gt;
<span class="lineNum">      14 </span>            : #include &lt;boost/config.hpp&gt;
<span class="lineNum">      15 </span>            : #include &lt;boost/throw_exception.hpp&gt;
<span class="lineNum">      16 </span>            : #include &lt;boost/mpl/if.hpp&gt;
<span class="lineNum">      17 </span>            : #include &lt;boost/type_traits/is_base_of.hpp&gt;
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : namespace boost {
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : //! Namespace containing constrained_value template and types
<span class="lineNum">      22 </span>            : namespace CV {
<span class="lineNum">      23 </span>            :   //! Represent a min or max violation type
<span class="lineNum">      24 </span>            :   enum violation_enum {min_violation, max_violation};
<span class="lineNum">      25 </span>            :   
<span class="lineNum">      26 </span>            :   //! A template to specify a constrained basic value type
<span class="lineNum">      27 </span>            :   /*! This template provides a quick way to generate
<span class="lineNum">      28 </span>            :    *  an integer type with a constrained range.  The type
<span class="lineNum">      29 </span>            :    *  provides for the ability to specify the min, max, and
<span class="lineNum">      30 </span>            :    *  and error handling policy.
<span class="lineNum">      31 </span>            :    *  
<span class="lineNum">      32 </span>            :    *  &lt;b&gt;value policies&lt;/b&gt;
<span class="lineNum">      33 </span>            :    *  A class that provides the range limits via the min and
<span class="lineNum">      34 </span>            :    *  max functions as well as a function on_error that 
<span class="lineNum">      35 </span>            :    *  determines how errors are handled.  A common strategy
<span class="lineNum">      36 </span>            :    *  would be to assert or throw and exception.  The on_error
<span class="lineNum">      37 </span>            :    *  is passed both the current value and the new value that
<span class="lineNum">      38 </span>            :    *  is in error.
<span class="lineNum">      39 </span>            :    *
<span class="lineNum">      40 </span>            :    */
<span class="lineNum">      41 </span>            :   template&lt;class value_policies&gt;
<span class="lineNum">      42 </span>            :   class constrained_value {
<span class="lineNum">      43 </span>            :   public:
<span class="lineNum">      44 </span>            :     typedef typename value_policies::value_type value_type;
<span class="lineNum">      45 </span>            :     //    typedef except_type exception_type;
<span class="lineNum">      46 </span><span class="lineCov">     124218 :     constrained_value(value_type value) : value_((min)())</span>
<span class="lineNum">      47 </span>            :     {
<span class="lineNum">      48 </span><span class="lineCov">     124218 :       assign(value);</span>
<span class="lineNum">      49 </span>            :     }
<span class="lineNum">      50 </span>            :     constrained_value&amp; operator=(value_type v)
<span class="lineNum">      51 </span>            :     {
<span class="lineNum">      52 </span>            :       assign(v); 
<span class="lineNum">      53 </span>            :       return *this;
<span class="lineNum">      54 </span>            :     }
<span class="lineNum">      55 </span>            :     //! Return the max allowed value (traits method)
<span class="lineNum">      56 </span>            :     static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::max)();}
<span class="lineNum">      57 </span>            :     //! Return the min allowed value (traits method)
<span class="lineNum">      58 </span>            :     static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::min)();}
<span class="lineNum">      59 </span>            :     //! Coerce into the representation type
<span class="lineNum">      60 </span>            :     operator value_type() const {return value_;}
<span class="lineNum">      61 </span>            :   protected:
<a name="62"><span class="lineNum">      62 </span>            :     value_type value_;</a>
<span class="lineNum">      63 </span>            :   private:
<span class="lineNum">      64 </span><span class="lineCov">     124218 :     void assign(value_type value)</span>
<span class="lineNum">      65 </span>            :     {
<span class="lineNum">      66 </span>            :       //adding 1 below gets rid of a compiler warning which occurs when the 
<span class="lineNum">      67 </span>            :       //min_value is 0 and the type is unsigned....
<span class="lineNum">      68 </span><span class="lineCov">     124218 :       if (value+1 &lt; (min)()+1) {</span>
<span class="lineNum">      69 </span><span class="lineNoCov">          0 :         value_policies::on_error(value_, value, min_violation);</span>
<span class="lineNum">      70 </span>            :         return;
<span class="lineNum">      71 </span>            :       }
<span class="lineNum">      72 </span><span class="lineCov">     124218 :       if (value &gt; (max)()) {</span>
<span class="lineNum">      73 </span><span class="lineNoCov">          0 :         value_policies::on_error(value_, value, max_violation);</span>
<span class="lineNum">      74 </span>            :         return;
<span class="lineNum">      75 </span>            :       }
<span class="lineNum">      76 </span><span class="lineCov">     124218 :       value_ = value;</span>
<span class="lineNum">      77 </span>            :     }
<span class="lineNum">      78 </span>            : };
<span class="lineNum">      79 </span>            : 
<span class="lineNum">      80 </span>            :   //! Template to shortcut the constrained_value policy creation process
<span class="lineNum">      81 </span>            :   template&lt;typename rep_type, rep_type min_value, 
<span class="lineNum">      82 </span>            :            rep_type max_value, class exception_type&gt;
<span class="lineNum">      83 </span>            :   class simple_exception_policy
<span class="lineNum">      84 </span>            :   {
<span class="lineNum">      85 </span>            :     struct exception_wrapper : public exception_type
<span class="lineNum">      86 </span>            :     {
<span class="lineNum">      87 </span>            :       // In order to support throw_exception mechanism in the BOOST_NO_EXCEPTIONS mode,
<span class="lineNum">      88 </span>            :       // we'll have to provide a way to acquire std::exception from the exception being thrown.
<span class="lineNum">      89 </span>            :       // However, we cannot derive from it, since it would make it interceptable by this class,
<span class="lineNum">      90 </span>            :       // which might not be what the user wanted.
<span class="lineNum">      91 </span>            :       operator std::out_of_range () const
<span class="lineNum">      92 </span>            :       {
<span class="lineNum">      93 </span>            :         // TODO: Make the message more descriptive by using arguments to on_error
<span class="lineNum">      94 </span>            :         return std::out_of_range(&quot;constrained value boundary has been violated&quot;);
<span class="lineNum">      95 </span>            :       }
<span class="lineNum">      96 </span>            :     };
<span class="lineNum">      97 </span>            : 
<span class="lineNum">      98 </span>            :     typedef typename mpl::if_&lt;
<span class="lineNum">      99 </span>            :       is_base_of&lt; std::exception, exception_type &gt;,
<span class="lineNum">     100 </span>            :       exception_type,
<span class="lineNum">     101 </span>            :       exception_wrapper
<span class="lineNum">     102 </span>            :     &gt;::type actual_exception_type;
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span>            :   public:
<span class="lineNum">     105 </span>            :     typedef rep_type value_type;
<a name="106"><span class="lineNum">     106 </span>            :     static rep_type min BOOST_PREVENT_MACRO_SUBSTITUTION () { return min_value; }</a>
<span class="lineNum">     107 </span>            :     static rep_type max BOOST_PREVENT_MACRO_SUBSTITUTION () { return max_value; }
<span class="lineNum">     108 </span><span class="lineNoCov">          0 :     static void on_error(rep_type, rep_type, violation_enum)</span>
<span class="lineNum">     109 </span>            :     {
<span class="lineNum">     110 </span><span class="lineNoCov">          0 :       boost::throw_exception(actual_exception_type());</span>
<span class="lineNum">     111 </span>            :     }
<span class="lineNum">     112 </span>            :   };
<span class="lineNum">     113 </span>            : 
<span class="lineNum">     114 </span>            : 
<span class="lineNum">     115 </span>            : 
<span class="lineNum">     116 </span>            : } } //namespace CV
<span class="lineNum">     117 </span>            : 
<span class="lineNum">     118 </span>            : 
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            : 
<span class="lineNum">     121 </span>            : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
